package com.glsc.ngateway.common.api.flowable.dto.demand;

import com.glsc.ngateway.common.api.flowable.dto.CreatedTaskInfoDto;
import com.glsc.ngateway.common.api.flowable.dto.demand.node.ProcessNode;
import com.glsc.ngateway.common.api.flowable.dto.demand.node.ProcessNodeInfo;
import com.glsc.ngateway.common.api.flowable.dto.demand.node.ProcessNodeStatus;
import com.glsc.ngateway.common.api.flowable.resp.ResponseCommentDto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lixing
 * 特定的一个需求流程所有使用的信息
 */
public class AllProcessInfo {

    /*所有节点的信息*/
    Map<ProcessNode, List<ProcessNodeInfo>> flowmap = new HashMap<ProcessNode, List<ProcessNodeInfo>>();

    /*包含当前节点信息，及业务要素信息*/
    DemandManagementDto glRequirement;

    /*comments信息*/
    List<ResponseCommentDto> comments = new ArrayList<ResponseCommentDto>();


    public DemandManagementDto getGlRequirement() {
        return glRequirement;
    }

    public void setGlRequirement(DemandManagementDto glRequirement) {
        this.glRequirement = glRequirement;
    }

    public Map<ProcessNode, List<ProcessNodeInfo>> getFlowmap() {
        return flowmap;
    }

    public void setFlowmap(Map<ProcessNode, List<ProcessNodeInfo>> flowmap) {
        this.flowmap = flowmap;
    }

    public List<ResponseCommentDto> getComments() {
        return comments;
    }

    public void setComments(List<ResponseCommentDto> comments) {
        this.comments = comments;
    }


    public void addNullNode(ProcessNode node) {
        if (!flowmap.containsKey(node)) {
            flowmap.put(node, new ArrayList<ProcessNodeInfo>());
        }
    }


    /**
     * 需要注意：只有节点onlineTask/signatureTask是可能存在多个的，其他只需要排在前面的第一个节点状态即可
     *
     * @param r
     */
    public void addNode(CreatedTaskInfoDto r) {

        ProcessNode node = ProcessNode.getProcessNode(r.getTaskName());
        ProcessNodeStatus status = ProcessNodeStatus.getProcessNodeStatus(r.getStatus());

        if (!flowmap.containsKey(node)) {
            flowmap.put(node, new ArrayList<ProcessNodeInfo>() {{
                add(new ProcessNodeInfo(r.getTaskId(), r.getAssignee(), r.getAssigneeName(), status));
            }});
        } else if (ProcessNode.onlineTask.equals(node) || ProcessNode.signatureTask.equals(node)) {
            flowmap.get(node).add(new ProcessNodeInfo(r.getTaskId(), r.getAssignee(), r.getAssigneeName(), status));
        }


    }


}
